﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
 
namespace StuEdu.Web.TelBook
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int addressId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(addressId);
				}
			}
		}
			
	private void ShowInfo(int addressId)
	{
		StuEdu.BLL.TelBook bll=new StuEdu.BLL.TelBook();
		StuEdu.Model.TelBook model=bll.GetModel(addressId);
		this.lbladdressId.Text=model.addressId.ToString();
		this.txttelNum.Text=model.telNum;
		this.txtuserName.Text=model.userName;
		this.txtuserQq.Text=model.userQq;
		this.txtuserMail.Text=model.userMail;
		this.txtworkAddress.Text=model.workAddress;
		this.txtcompanyAddress.Text=model.companyAddress;
		this.txtcompanyTel.Text=model.companyTel;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txttelNum.Text.Trim().Length==0)
			{
				strErr+="telNum不能为空！\\n";	
			}
			if(this.txtuserName.Text.Trim().Length==0)
			{
				strErr+="userName不能为空！\\n";	
			}
			if(this.txtuserQq.Text.Trim().Length==0)
			{
				strErr+="userQq不能为空！\\n";	
			}
			if(this.txtuserMail.Text.Trim().Length==0)
			{
				strErr+="userMail不能为空！\\n";	
			}
			if(this.txtworkAddress.Text.Trim().Length==0)
			{
				strErr+="workAddress不能为空！\\n";	
			}
			if(this.txtcompanyAddress.Text.Trim().Length==0)
			{
				strErr+="companyAddress不能为空！\\n";	
			}
			if(this.txtcompanyTel.Text.Trim().Length==0)
			{
				strErr+="companyTel不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int addressId=int.Parse(this.lbladdressId.Text);
			string telNum=this.txttelNum.Text;
			string userName=this.txtuserName.Text;
			string userQq=this.txtuserQq.Text;
			string userMail=this.txtuserMail.Text;
			string workAddress=this.txtworkAddress.Text;
			string companyAddress=this.txtcompanyAddress.Text;
			string companyTel=this.txtcompanyTel.Text;


			StuEdu.Model.TelBook model=new StuEdu.Model.TelBook();
			model.addressId=addressId;
			model.telNum=telNum;
			model.userName=userName;
			model.userQq=userQq;
			model.userMail=userMail;
			model.workAddress=workAddress;
			model.companyAddress=companyAddress;
			model.companyTel=companyTel;

			StuEdu.BLL.TelBook bll=new StuEdu.BLL.TelBook();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
